#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void FindMaxMinid(int arr[], int n)
{
	int ct = 0;
	int max = 0;
	int min = 0;
	for (ct; ct < n-1; ct++)
	{
		if (arr[ct + 1] > arr[ct])
			max = ct + 1;
	}
	for (ct = 0; ct < n - 1; ct++)
	{
		if (arr[ct + 1] < arr[ct])
			min = ct + 1;
	}
	int tmp = arr[max];
	arr[max] = arr[min];
	arr[min] = tmp;
	for (ct = 0; ct < n; ct++)
	{
		printf("%d ",arr[ct]);
	}
}
int main()
{
	int arr[50] = { 0 };
	int n = 0;
	scanf("%d", &n);
	int i = 0;
	for (i; i < n; i++)
	{
		scanf("%d", &arr[i]);
	}
	FindMaxMinid(arr, n);
	return 0;
}